from typing import Dict, List

from mg_app_framework import get_context, update_context

from common_bind_service.models.container_config import ContainerMarkConfig
from common_bind_service.models.dict_model.mq.device_config_entity import DeviceConfigEntity


class ContextUtils:
    _device_code_info_dict_key = 'device_code_info_dict'  # 设备编码对应生产单元
    _container_mark_config = 'container_mark_config'  # 存储码值规则的信息
    _dev_code_table_number_map = 'dev_code_table_number_map'  # 存储设备编码和机台号的映射关系

    @classmethod
    def get_device_code_info_dict(cls) -> Dict[str, DeviceConfigEntity]:
        return get_context(cls._device_code_info_dict_key)

    @classmethod
    def set_device_code_info_dict(cls, data):
        return update_context(cls._device_code_info_dict_key, data)

    @classmethod
    def get_container_mark_config(cls) -> List[ContainerMarkConfig]:
        return get_context(cls._container_mark_config)

    @classmethod
    def set_container_mark_config(cls, data: List[ContainerMarkConfig]):
        return update_context(cls._container_mark_config, data)

    @classmethod
    def get_dev_code_table_number_map(cls) -> Dict[str, str]:
        return get_context(cls._dev_code_table_number_map)

    @classmethod
    def set_dev_code_table_number_map(cls, data: Dict[str, str]):
        return update_context(cls._dev_code_table_number_map, data)
